package com.bookstore.admin.products.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bookstore.admin.products.dao.IAdminProductsDao;
import com.bookstore.admin.products.service.IAdminProductService;
import com.bookstore.commons.beans.Product;
import com.bookstore.commons.beans.ProductList;
import com.bookstore.commons.vo.AdminProduct;
import com.bookstore.utils.PageModel;

@Service
public class AdminProductsServiceImpl implements IAdminProductService {

	@Autowired
	private IAdminProductsDao adminProductsDao;
	
	@Override
	public int findCountByManyCondition(AdminProduct condition) {
		
		return adminProductsDao.selectCountByManyCondition(condition);
	}

	@Override
	public List<Product> findProductsByManyConfition(AdminProduct condition, PageModel pageModel) {

			Map<String ,Object> map = new HashMap<>();
			map.put("start",pageModel.getFirstLimitParam() );
			map.put("size", pageModel.getPageSize());
			
		
		if(condition != null){
			map.put("condition", condition);
			return adminProductsDao.selectProductsByManyCondition(map);
		}else{
			return adminProductsDao.selectAllProducts(map);
		}
		
	}

	@Override
	public Product findProductById(String id) {
		return adminProductsDao.selectProductById(id);
	}

	@Override
	public int modifyProductById(Product product) {
		return adminProductsDao.updateProduct(product);
	}

	@Override
	public int addProduct(Product product) {
		return adminProductsDao.insertProduct(product);
	}

	@Override
	public int removeProductById(String id) {
		return adminProductsDao.deleteProduct(id);
	}

	@Override
	public List<ProductList> findProductList(String year, String month) {
		Map<String,Object> map = new HashMap<>();
		map.put("year", year);
		map.put("month", month);
		return adminProductsDao.selectProdcutList(map);
	}
	
	

}
